<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>广告分类管理</title>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="../css/style.css">
	<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="../plugins/bootstrap/js/bootstrap.min.js"></script>
    
</head>

<script type="text/javascript">
	getData();

	//查询
	function getData() {
		$.ajax({
			url: "/tbContentCategoryController/getFindAlls",
			type: "post",
			dataType: "json",
			data: {name : $("#aaa").val()},
			async: true,
			success: function (page) {
				var SpecificPrint = page.data;
				var table = "<table class=\"table table-bordered table-striped table-hover dataTable\">";
				table += "<tr>";
				table += "<th></th>";
				table += "<th class=\"sorting_asc\">分类ID</th>";
				table += "<th class=\"sorting\">分类名称</th>";
				table += "<th class=\"text-center\">操作</th>";
				table += "</tr>";
				$(SpecificPrint).each(function (i,e) {
					table += "<tr>";
					table += "<td><input  name='box' type='checkbox' value='" + e.id + "'></td>";
					table += "<td>" + e.id + "</td>";
					table += "<td>" + e.name + "</td>";
					table += "<td><button type='button' class='btn bg-olive btn-xs' data-toggle='modal' onclick='toUpdate(" + e.id + ")' data-target='#updateModal'  >修改</button></td>"
					table += "</tr>";
				})
				table += "</table>";
				$("#dataList").html(table);

			},
			error: function () {
				alert("系统异常，请联系管理员");
			}
		})
	}


	//回显
	function toUpdate(id) {
		var q="";
		$.ajax({
			url:"/tbContentCategoryController/toUpdate",
			type:"get",
			datatype:"json",
			data:{id:id},
			async:true,
			success:function(result){

				$("#contentId").val(result.id);
				$("#contentName").val(result.name);
			},
			error:function(result){
				alert("系统异常，请联系管理员！！！");
			}
		})
	}


	//确认修改
	function updateTbContentCategory() {
		$.ajax({
			url:"/tbContentCategoryController/updateTbContentCategory",
			type:"get",
			datatype:"json",
			data:{name:$("#contentName").val(),id:$("#contentId").val()},
			async:true,
			success:function(result){
				alert(result.member+","+result.content+","+JSON.stringify(result.data));
                getData();
			},
			error:function(result){
				alert("系统异常，请联系管理员！！！");
			}
		})
	}




    //确认修改
    function saveTbContentCategory() {
        $.ajax({
            url:"/tbContentCategoryController/saveTbContentCategory",
            type:"get",
            datatype:"json",
            data:{name:$("#addcontentName").val()},
            async:true,
            success:function(result){
                alert(result.member+","+result.content+","+JSON.stringify(result.data));
                getData();
            },
            error:function(result){
                alert("系统异常，请联系管理员！！！");
            }
        })
    }


    //批删
    function deleteTbContentCategory(){
        var boxs=document.getElementsByName("box");
        var ids="";
        for (var i = 0; i < boxs.length; i++) {
            if(boxs[i].checked){
                ids+=",'"+boxs[i].value+"'";
            }
        }
        ids=ids.substring(1);
        $.ajax({
            url:"/tbContentCategoryController/deleteTbContentCategory",
            type:"get",
            datatype:"json",
            data:{ids:ids},
            async:true,
            success:function(result){
                alert(result.member+","+result.content+","+JSON.stringify(result.data));
                getData();
            },
            error:function(result){
                alert("系统异常，请联系管理员！！！");
            }
        })
    }

</script>

<body class="hold-transition skin-red sidebar-mini"  >
  <!-- .box-body -->
                
                    <div class="box-header with-border">
                        <h3 class="box-title">广告分类管理</h3>
                    </div>

                    <div class="box-body">

                        <!-- 数据表格 -->
                        <div class="table-box">

                            <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-default"  title="新建" data-toggle="modal" data-target="#editModal" ><i class="fa fa-file-o"></i> 新建</button>
                                        <button type="button" class="btn btn-default" onclick="deleteTbContentCategory()" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>
                                        <button type="button" class="btn btn-default" title="开启" onclick='confirm("你确认要开启吗？")'><i class="fa fa-check"></i> 开启</button>
                                        <button type="button" class="btn btn-default" title="屏蔽" onclick='confirm("你确认要屏蔽吗？")'><i class="fa fa-ban"></i> 屏蔽</button>
                                        <button type="button" class="btn btn-default"  title="刷新" onclick="getData()"><i class="fa fa-refresh"></i> 刷新</button>
                                    </div>
                                </div>
                            </div>
                            <div class="box-tools pull-right">
                                <div class="has-feedback">
							        名称：<input id="aaa">	<button class="btn btn-default" onclick="getData()">查询</button>
                                </div>
                            </div>
                            <!--工具栏/-->

			                  <!--数据列表-->
			                  <table id="dataList" class="table table-bordered table-striped table-hover dataTable">

			                  </table>
			                  <!--数据列表/--> 
                        </div>
                        <!-- 数据表格 /-->
                     </div>
                    <!-- /.box-body -->
	            <!-- 分页 -->
				
				                
<!-- 修改编辑窗口 -->
<div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" >
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
			<h3 id="myModalLabel">广告分类编辑</h3>
		</div>
		<div class="modal-body">
			<input type="hidden" id="contentId">
			<table class="table table-bordered table-striped"  width="800px">
		      	<tr>
		      		<td>分类名称</td>
		      		<td><input  class="form-control" placeholder="分类名称" id="contentName">  </td>
		      	</tr>

			 </table>				
			
		</div>
		<div class="modal-footer">						
			<button class="btn btn-success"  data-dismiss="modal" onclick="updateTbContentCategory()" aria-hidden="true">保存</button>
			<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
		</div>
	  </div>
	</div>
</div>




  <!-- 增加编辑窗口 -->
  <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog" >
          <div class="modal-content">
              <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                  <h3 id="myModalLabel1">广告分类编辑</h3>
              </div>
              <div class="modal-body">
                  <table class="table table-bordered table-striped"  width="800px">
                      <tr>
                          <td>分类名称</td>
                          <td><input  class="form-control" placeholder="分类名称" id="addcontentName">  </td>
                      </tr>

                  </table>

              </div>
              <div class="modal-footer">
                  <button class="btn btn-success"  data-dismiss="modal" onclick="saveTbContentCategory()" aria-hidden="true">保存</button>
                  <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
              </div>
          </div>
      </div>
  </div>
</body>

</html>